package com.tjcd.project.library_base.base.model;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;

import com.hjq.http.config.IRequestApi;
import com.hjq.http.listener.OnHttpListener;

/**
 * @Author jiangKunKun
 * @CreateDate 2024/9/27
 * @Description
 * @SpittingGrooves
 */
public abstract class BaseViewModel extends AndroidViewModel implements LifecycleOwner, OnHttpListener<Object> {
    private final LifecycleRegistry mLifecycle = new LifecycleRegistry(this);

    public BaseViewModel(@NonNull Application application) {
        super(application);
        mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
        mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
    }

    @NonNull
    @Override
    public Lifecycle getLifecycle() {
        return mLifecycle;
    }

    @Override
    public void onHttpSuccess(Object result) {

    }


    @Override
    public void onHttpStart(@NonNull IRequestApi api) {
//        OnHttpListener.super.onHttpStart(api);
    }

    @Override
    public void onHttpEnd(@NonNull IRequestApi api) {
//        OnHttpListener.super.onHttpEnd(api);
    }

    @Override
    public void onHttpFail(@NonNull Throwable throwable) {

    }
}
